define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/attribute/index',
                    add_url: 'order/attribute/add',
                    edit_url: 'order/attribute/edit',
                    del_url: 'order/attribute/del',
                    multi_url: 'order/attribute/multi',
                    table: 'order_attribute',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'category.myPid.myPid.title', title: __('一级品类'), operate: false},
                        {field: 'category.myPid.title', title: __('二级品类'), operate: false},
                        {field: 'category.title', title: __('三级品类'), operate: false},
                        {field: 'title', title: __('Title'),operate:"LIKE"},
                        {field: 'price', title: __('Price'), operate: 'BETWEEN'},
                        {field: 'weigh', title: __('Weigh'), sortable: true, operate: false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});